define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'adminlte'], function ($, undefined, Backend, Table, Form, Adminlte) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'building/index',
                    add_url: 'building/add',
                    edit_url: 'building/edit',
                    del_url: 'building/del',
                    multi_url: 'building/multi',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                sortName: 'building.id',
                columns: [
                    [
                        {field: 'state', checkbox: true, },
                        {
                            field: 'garden_id', title: __('学校/园区'), searchList: function (column) {
                                return Template('schoolTpl', {});
                            }, formatter: function (value, row, index) {
                                return '无';
                            }, visible: false
                        },
                        {field: 'number', title: __('Number')},
                        {field: 'name', title: __('Name')},
                        {field: 'school_name', title: __('学校'), operate: false},
                        {field: 'garden_name', title: __('Garden'), operate: false},
                        {field: 'floor', title: __('Floor'), operate: false},
                        {field: 'floor_room_count', title: __('Floor Room Count'), operate: false},
                        {field: 'type_text', title: __('Type'), operate: false},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ],
                commonSearch: true,
                searchFormVisible: true,
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Form.api.bindevent($("form[role=form]"));
        },
        edit: function () {
            Form.api.bindevent($("form[role=form]"));
        }
    };
    return Controller;
});